package com.gnerv.battle.boot.module.base.controller;

import com.gnerv.battle.boot.common.base.model.RestResult;
import com.gnerv.battle.boot.module.base.business.DictItemBusiness;
import com.gnerv.battle.boot.module.base.model.dto.DictItemCreateDTO;
import com.gnerv.battle.boot.module.base.model.dto.DictItemDTO;
import com.gnerv.battle.boot.module.base.model.dto.DictItemUpdateDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/manage/dict/item")
public class DictItemController {

    private final DictItemBusiness dictItemBusiness;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody DictItemCreateDTO dictItemCreateDTO) {
        return dictItemBusiness.create(dictItemCreateDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return dictItemBusiness.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody DictItemUpdateDTO dictItemUpdateDTO) {
        return dictItemBusiness.updateByUkId(dictItemUpdateDTO);
    }

    @GetMapping(value = "")
    public RestResult<DictItemDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return dictItemBusiness.selectByUkId(ukId);
    }

    @GetMapping(value = "list/dict")
    public RestResult<List<DictItemDTO>> listByDictUkId(@RequestParam(value = "dictUkId") String dictUkId) {
        return dictItemBusiness.listByDictUkId(dictUkId);
    }

}
